package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.BusinessDao;
import com.foreknow.elm.dao.UserDao;
import com.foreknow.elm.dao.impl.BusinessDaoImpl;
import com.foreknow.elm.dao.impl.UserDaoImpl;
import com.foreknow.elm.po.Business;
import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.util.DBUtil;

import java.sql.SQLException;

/**
 * @author shkstart
 * @create 2021-08-26 14:18
 */
public class UserServiceImpl implements UserService {
    @Override
    public User SvgetUserByIdByPass(String userId, String password) {

        User user = null;
        UserDao dao = new UserDaoImpl();

            DBUtil.getConnection();
        try {
            user= dao.getUserByIdByPass(userId, password);
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            DBUtil.close();
        }

       return null;

    }

    @Override
    public int SvgetUserById(String userId) {
        User user=null;
        UserDao dao=new UserDaoImpl();
        try {
            int userById = dao.getUserById(userId);
            return userById;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            DBUtil.close();
        }
        return 0;
    }

    @Override
    public int SvsaveUser(String userId, String password, String userName, int  userSex) {
        User user=null;
        UserDao dao=new UserDaoImpl();
        int i = 0;
        try {
            i = dao.saveUser(userId, password, userName, userSex);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            DBUtil.close();
        }
      return 0;
    }
}
